package com.biostime.rpc.terminal.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.biostime.rpc.terminal.repository.TerminalVoRepository;
import com.biostime.rpc.terminal.service.bean.TerminalBean;
import com.biostime.rpc.terminal.thrift.inout.FTerminal;
import com.biostime.rpc.terminal.thrift.inout.Location;
import com.biostime.rpc.terminal.util.BeanPraser;
import com.biostime.rpc.terminal.util.MapperUtils;

/**
 * 类功能描述: 门店服务
 *
 * @version 1.0
 * @author zhuhaitao
 * @createDate 2015年12月21日 下午3:12:55
 */
@Service
public class TerminalVoService {
	@Autowired
	private TerminalVoRepository terminalVoRepository;
	@Autowired
	private MapperUtils mapper;

	/**
	 * 方法描述: 查询附近门店
	 *
	 * @param location
	 * @param distance
	 * @param terminalCode
	 * @param terminalName
	 * @return
	 * @author zhuhaitao
	 * @createDate 2015年12月21日 下午3:12:05
	 */
	public List<FTerminal> findNearTerminals(Location location, Long distance, String terminalCode, String terminalName, int isStaff) {
		List<TerminalBean> beanList = new ArrayList<TerminalBean>();
		List<Map<String, Object>> list = terminalVoRepository.findNearTerminals(location, distance, terminalCode, terminalName, isStaff);
		if (null != list && !list.isEmpty()) {
			for (Map<String, Object> m : list) {
				beanList.add((TerminalBean) BeanPraser.copyFromMap(m, TerminalBean.class));
			}
		}
		return mapper.map(beanList, FTerminal.class);
	}
}
